package com.zh.note.huawei.twohundred.可以组成网络的服务器;

import java.util.Scanner;

/**
 * @Author: zhanghuan
 * @date: 2023/8/28 10:41
 * @description: create it
 */
public class Main {
    public static int[][] direction = {{-1, 0}, {0, 1}, {0, -1}, {1, 0}};
    public static int row = 0;
    public static int col = 0;


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        row = sc.nextInt();
        col = sc.nextInt();
        int[][] matrix = new int[row][col];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                matrix[i][j] = sc.nextInt();
            }
        }
        int res = 0;
        boolean[][] visited = new boolean[row][col];
        for (int i = 0; i < row; i++) {
            for (int j = 0; j < col; j++) {
                res = Math.max(res, dfs(i, j, matrix, visited));
            }
        }
        System.out.println(res);
    }

    private static int dfs(int x, int y, int[][] matrix, boolean[][] visited) {
        if (x < 0 || x >= row || y < 0 || y >= col || matrix[x][y] != 1 || visited[x][y] == true) {
            return 0;
        }
        int res = matrix[x][y];
        visited[x][y] = true;
        for (int[] dir : direction) {
            int i = dir[0] + x;
            int j = dir[1] + y;
            res += dfs(i, j, matrix, visited);
        }
        return res;
    }
}
